import BaseUtil from '@/BaseUtil';
import ObjectPool from '@/ObjectPool';

export default class VestCommon {
    private static pool: ObjectPool<unit> = new ObjectPool<unit>(VestCommon.poolCreator, VestCommon.poolDestroyer);
    private static poolCreator() {
        return CreateUnit(Player(0), 'ewnv', 0, 0, 0);
    }
    private static poolDestroyer(u: unit) {
        SetUnitAnimation(u, 'Death');
        BaseUtil.runLater(1, () => {
            SetUnitX(u, 3600);
            SetUnitY(u, -3600);
            SetUnitFlyHeight(u, -300, 2000);
        });
    }
    static 取马甲() {
        let u = VestCommon.pool.borrowObject();
        SetUnitFlyHeight(u, 60, 2000);
        SetUnitAnimation(u, 'Birth');
        return u;
    }
    static returnVest(u: unit) {
        VestCommon.pool.returnObject(u);
    }
    static 取马甲并设置(x: number, y: number, facing: number) {
        let u = VestCommon.取马甲();
        SetUnitX(u, x);
        SetUnitY(u, y);
        EXSetUnitFacing(u, facing);
        return u;
    }
    static 取无模型马甲() {
        let u = VestCommon.pool.borrowObject();
        SetUnitLifePercentBJ(u, 100);
        SetUnitManaPercentBJ(u, 100);
        DzSetUnitModel(u, '');
        return u;
    }
    static getNoneModelVest(x: number, y: number, facing: number) {
        let u = VestCommon.取无模型马甲();
        SetUnitX(u, x);
        SetUnitY(u, y);
        EXSetUnitFacing(u, facing);
        return u;
    }
}
